package com.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.Role;
import com.hr.mapper.RoleMapper;
import com.hr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public Page<Role> queryAll(Page<Role> page) {
        //        //分页参数
//        Page<Users> page = new Page<>();
//        //设置当前页码
//        page.setCurrent(2);
//        //每页显示记录数
//        page.setSize(5);
        //使用mybatis查询一页的方法
        QueryWrapper<Role> wrapper=new QueryWrapper<Role>();
        page = roleMapper.selectPage(page,wrapper);
        return page;
    }

    /**
     * 保存/修改
     * @param role
     * @return
     */
    @Override
    public boolean save(Role role) {
        int row=0;
        if(role.getRid()==null){
            row = roleMapper.insert(role);
        }else{
            row = roleMapper.updateById(role);
        }

        return row>0;
    }

    /**
     * 删除
     * @param rid
     * @return
     */
    @Override
    public boolean del(Integer rid) {
        int i = roleMapper.deleteById(rid);
        return i>0;
    }

    /**
     * 单值查询
     * @param rid
     * @return
     */
    @Override
    public Role queryById(Integer rid) {
        Role role = roleMapper.selectById(rid);
        return role;
    }
}
